<template>
  <div class="login-wrap">
    <div class="model"></div>
    <div class="ms-title">国朗项目管理
      <div style="margin: 20px;">
        <h1>{{$t("message.title")}}</h1>


        <input style="width: 300px;" class="form-control" :placeholder="$t('placeholder.enter')">


        <ul>
          <li v-for="brand in brands">{{brand}}</li>
        </ul>
      </div>
      {{$t('message.hello')}}-------------

<b @click="switchLang('cn')">中文</b>  <b @click="switchLang('en')">英文</b>
    </div>
    <div class="ms-login">
      <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
        <!--<h3 class="title">系统登录</h3>-->
        <el-form-item prop="userName">
          <el-input type="text" v-model="ruleForm2.userName" auto-complete="off" placeholder="账号"></el-input>
        </el-form-item>
        <el-form-item prop="userPwd">
          <el-input type="password" v-model="ruleForm2.userPwd" auto-complete="off" placeholder="密码"></el-input>
        </el-form-item>
        <el-checkbox v-model="checked" checked class="remember">记住密码</el-checkbox>
        <el-form-item style="width:100%;">
          <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">登录</el-button>
          <!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
    // import insurance from '../../api/insurance';
  export default {
    data() {
      return {
        lang: 'en',
        brands: [this.$t('brands.nike'), this.$t('brands.adi'), this.$t('brands.nb'), this.$t('brands.ln')],
        logining: false,
        ruleForm2: {
            userName: '',
            userPwd: ''
        },
        rules2: {
            userName: [
            { required: true, message: '请输入账号', trigger: 'blur' },
          ],
            userPwd: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ]
        },
        checked: true
      };
    },
    methods: {
      switchLang(lang)  {
        this.lang = lang;
        this.$i18n.locale = this.lang
      },
      handleReset2() {
        this.$refs.ruleForm2.resetFields();
      },
      handleSubmit2(ev) {
        var that = this;
          that.$refs.ruleForm2.validate((valid) => {
          if (valid) {
              that.logining = true;
              var data = JSON.stringify({ usrname: that.ruleForm2.userName, pwd: that.ruleForm2.userPwd });
              $.ajax(insurance.posturl2+"user/login",{
                  'data': data,
                  headers: {'Content-Type': 'application/json;charset=UTF-8'},
                  'type': 'POST',
                  success:function (res) {
                      res = JSON.parse(res);
                      if(res.isSuccess){
                          that.$message({ message: '登录成功',type: 'success'});
                          var d = res.Content;
                          sessionStorage.setItem('user', d);
                          sessionStorage.setItem('isRembers', that.checked);
                          console.log(d);
                          that.$router.push({ path: '/posiStuList' });
                      }else{
                          that.$message({ message: '登录失败',type: 'success'});
                      }
                      that.logining = false;
                  }
              });
          } else {
            return false;
          }
        });
      }
    },
    mounted(){
        if (sessionStorage.getItem('user')) {
            this.ruleForm2.userName = JSON.parse(sessionStorage.getItem('user')).usrname;
            this.ruleForm2.userPwd = JSON.parse(sessionStorage.getItem('user')).pwd;
        }
    }
  }
</script>


<style >

</style>
